package org.mineground.commands.irc;

import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.World;
import org.jibble.pircbot.Colors;
import org.jibble.pircbot.User;
import org.mineground.Main;
import org.mineground.Utilities;
import org.mineground.handlers.irc.CommandExecutor;
import org.mineground.handlers.irc.UserLevel;

public class Weather implements CommandExecutor {
    @Override
    public void onCommand(User sender, UserLevel level, String channel, String command, String args[]) {
	if (level.compareTo(UserLevel.IRC_HOP) < 0) {
	    return;
        }

	if (args.length < 1) {
	    Main.getInstance().getIRCHandler().sendMessage(channel, Colors.RED + "* Usage:" + Colors.NORMAL + " !weather [sun/rain]");
	    return;
	}
        
	List<World> worlds = Main.getInstance().getServer().getWorlds();

	if (args[0].equalsIgnoreCase("sun")) {
	    worlds.get(0).setStorm(false);
	    worlds.get(0).setWeatherDuration(1000000);
	    Utilities.sendMessageToAll(ChatColor.GRAY + "* (IRC) " + sender.getNick() + " has changed the weather to sun.");
	}

	else if (args[0].equals("rain")) {
	    worlds.get(0).setStorm(true);
	    worlds.get(0).setWeatherDuration(1000000);
	    Utilities.sendMessageToAll(ChatColor.GRAY + "* (IRC) " + sender.getNick() + " has changed the weather to rain.");
	}

	else {
	    Main.getInstance().getIRCHandler().sendMessage(channel, Colors.RED + "* Usage:" + Colors.NORMAL + " !weather [sun/rain]");
	    return;
	}

	Main.getInstance().getIRCHandler().sendMessage(channel, Colors.DARK_GREEN + "* Weather in " + worlds.get(0).getName() + " has been changed.");
    }
}